﻿Zepto(function($) {
	var enalbeGeticode = true;
	if($('#geticode').length > 0) {
		$('#geticode').click(function(e) {
			zsmm.isValidated = true;
			validateInput("mobile");
			validatePhone("mobile");
			if(!zsmm.isValidated) {
				return false;
			}
			var phone = $.trim($('input[name="mobile"]').eq(0).val());
			if(enalbeGeticode) {
				enalbeGeticode = false;
				var i = 60;
				var obj = $(this);
				obj.text(i + '秒后重试').addClass('disabled');
				var intval = setInterval(function() {
					i -= 1;
					obj.text(i + '秒后重试');
					if(i <= 0) {
						clearInterval(intval);
						obj.text('获取短信验证码').removeClass('disabled');
						enalbeGeticode = true;
						return;
					}
				}, 1000);
				$.ajax({
					url: "/user/send",
					type: "post",
					dataType: "json",
					data: {
						mobile: phone
					},
					success: function(res) {
						baiaimama.Toast.New(res.msg);
					}
				});
			}
		});
	}
	$("button[type='submit']").click(function(e) {
		e.preventDefault();
		zsmm.isValidated = true;
		var phone = $.trim($('input[name="mobile"]').eq(0).val());
		var code = $.trim($('input[name="code"]').eq(0).val());
		//ajax校验验证码
		$.ajax({
			url: "/user/validcode",
			type: "post",
			dataType: "json",
			data: {
				mobile: phone,
				code: code
			},
			success: function(res) {
				if(res.error == 0) {
					$("form").submit();
				} else {
					baiaimama.Toast.New(res.msg);
				}
			}
		});
	});
});